/*
 *   Copyright (c) 2010-2022, SIUFUNG
 */
package net.siufung.market.base.permit.controller.model.dto;

import com.google.common.collect.Lists;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;
import net.siufung.core.model.AbstractDto;
import net.siufung.market.base.permit.mapper.entity.RolePermit;

import java.util.List;

/**
 * <p>
 * 系统角色权限表 默认数据传参对象
 * </p>
 * @author 陈建峰
 * @since 2022-07-05 16:14:50
 */
@Slf4j
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="RolePermitDto", description="系统角色权限表默认数据传输对象")
public class RolePermitDto extends AbstractDto {

    private static final long serialVersionUID = -63839444489371283L;
    /**
     * 角色id
     */
    @ApiModelProperty(value = "角色id")
    private Integer roleId;

    /**
     * 权限id
     */
    @ApiModelProperty(value = "权限id")
    private List<Integer> permitIdList;

    /**
     * 租户id
     */
    @ApiModelProperty(value = "租户id")
    private Integer tenantId;


    /**
     * 转化成数据库实体
     * @return RolePermit
     */
    public List<RolePermit> toList(){
        RolePermit rolePermit;
        List<RolePermit> rolePermitList = Lists.newArrayList();
        for (Integer permitId: permitIdList) {
            rolePermit = new RolePermit();
            rolePermit.setRoleId(roleId);
            rolePermit.setPermitId(permitId);
            rolePermit.setTenantId(tenantId);
            rolePermitList.add(rolePermit);
        }
        return rolePermitList;
    }
}